package com.shell.arouter.ui.activity;

import android.content.Intent;
import android.view.KeyEvent;

import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.durian.base.frame.activity.BindFragmentSupport;
import com.durian.base.frame.titlebar.ISuperTitleBar;
import com.henanjianye.soon.communityo2o2.R;
import com.shell.arouter.ui.FragmentCommon;

import static com.shell.arouter.extend.ARouterPathKt.PATH_ACTIVITY_COMMON_BIND_FRAGMENT;

/**
 * 说明：ActivityCommonBind
 * <p/>
 * 作者：Fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2020/08/14 23:26
 * <p/>
 * 版本：version 1.0
 */
@Route(path = PATH_ACTIVITY_COMMON_BIND_FRAGMENT)
public class ActivityCommonBind extends ActivityCommon{
    private BindFragmentSupport mBindFragmentSupport = new BindFragmentSupport();

    @Override
    protected int getRootViewResID() {
        return R.layout.base_activity_bind_fragment;
    }

    @Override
    public void getIntentData(Intent intent) {
        super.getIntentData(intent);
        mBindFragmentSupport.getIntentData(intent);
    }

    @Override
    public void onInitStart() {
        if (mBindFragmentSupport.getFragment() != null) {
            replaceFragment(R.id.fl_content, mBindFragmentSupport.getFragment());
        }
    }

    @Override
    public ISuperTitleBar bindSuperTitleBar() {
        ISuperTitleBar titleBar = mBindFragmentSupport.bindSuperTitleBar();
        if (titleBar != null){
            return titleBar;
        }
        return super.bindSuperTitleBar();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mBindFragmentSupport.onActivityResult(requestCode,resultCode,data);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (mBindFragmentSupport.onKeyDown(keyCode,event)){
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onDestroy() {
        mBindFragmentSupport.onDestroy(this);
        super.onDestroy();
    }
//    ---------------------------------

    @Override
    public boolean isShowTitleBarBack() {
        if (mBindFragmentSupport.getFragment() instanceof FragmentCommon){
            return ((FragmentCommon)mBindFragmentSupport.getFragment()).isShowTitleBarBack();
        }
        return super.isShowTitleBarBack();
    }

    @Override
    public boolean isShowTitleBar() {
        if (mBindFragmentSupport.getFragment() instanceof FragmentCommon){
            return ((FragmentCommon)mBindFragmentSupport.getFragment()).isShowTitleBar();
        }
        return super.isShowTitleBar();
    }

    @Override
    public String bindTitleBarText() {
        if (mBindFragmentSupport.getFragment() instanceof FragmentCommon){
            return ((FragmentCommon)mBindFragmentSupport.getFragment()).bindTitleBarText();
        }
        return super.bindTitleBarText();
    }

    @Override
    public int bindTitleBarTextRes() {
        if (mBindFragmentSupport.getFragment() instanceof FragmentCommon){
            return ((FragmentCommon)mBindFragmentSupport.getFragment()).bindTitleBarTextRes();
        }
        return super.bindTitleBarTextRes();
    }
}
